﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using MySql.Data.MySqlClient;
using System.Data;

namespace SeniorProjectWS
{
    /// <summary>
    /// Summary description for Service2
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service2 : System.Web.Services.WebService
    {
        static String connection = @"server=192.168.1.250;User Id=seniorproject;password=seniorproject;database=seniorproject";

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public DataSet getAllShop_General()
        {
            MySqlConnection conn = new MySqlConnection(connection);
            conn.Open();
            String sql = "select id,shopname,address,avatar from phuong_shops";
            MySqlDataAdapter adapter = new MySqlDataAdapter(sql, connection);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            conn.Close();
            return ds;
        }

        [WebMethod]
        public DataSet getAllShop_Detail()
        {
            MySqlConnection conn = new MySqlConnection(connection);
            conn.Open();
            String sql = "select * from phuong_shops";
            MySqlDataAdapter adapter = new MySqlDataAdapter(sql, connection);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            conn.Close();
            return ds;
        }

        [WebMethod]
        public DataSet getShopFollowID(String id)
        {
            MySqlConnection conn = new MySqlConnection(connection);
            conn.Open();
            String sql = "select * from phuong_shops where id="+id;
            MySqlDataAdapter adapter = new MySqlDataAdapter(sql, connection);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            conn.Close();
            return ds;
        }

        [WebMethod]
        public DataSet getToDisplayOnMap()
        {
            MySqlConnection conn = new MySqlConnection(connection);
            conn.Open();
            String sql = "select id,shopname,address,latitude,longitude from phuong_shops";
            MySqlDataAdapter adapter = new MySqlDataAdapter(sql, connection);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            conn.Close();
            return ds;
        }
        [WebMethod]
        public DataSet getHotNews(String id,String catagory_id)
        {
            MySqlConnection conn = new MySqlConnection(connection);
            conn.Open();
            String sql = "SELECT A . * , I . * FROM phuong_newarticles AS A, phuong_images AS I WHERE A.phuong_shop_id ="+id+" AND A.id = I.phuong_newarticle_id AND A.phuong_catagory_id ="+catagory_id+" LIMIT 0 , 10  ";
            MySqlDataAdapter adapter = new MySqlDataAdapter(sql, connection);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            conn.Close();
            return ds;
        }
    }
}
